home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October : Technology Seed / ATS Oct. '97.toast / Navigation Services SDK 1.0a6 / Examples / Sampler / Sampler ƒ / Common.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-31  |  8.4 KB  |  333 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Common.h
  3.  
  4.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  5.  
  6. */
  7.  
  8. #ifndef __TYPES__
  9. #include <Types.h>
  10. #endif
  11.  
  12. #ifndef __DIALOGS__
  13. #include <Dialogs.h>
  14. #endif
  15.  
  16. #ifndef __LOWMEM__
  17. #include <LowMem.h>
  18. #endif
  19.  
  20. #ifndef __TEXTUTILS__
  21. #include <TextUtils.h>
  22. #endif
  23.  
  24. #ifndef __PRINTING__
  25. #include <Printing.h>
  26. #endif
  27.  
  28. #ifndef __APPLEEVENTS__
  29. #include <AppleEvents.h>
  30. #endif
  31.  
  32. #ifndef __QDOFFSCREEN__
  33. #include <QDOffscreen.h>
  34. #endif
  35.  
  36. #include "Navigation.h"
  37.  
  38. #ifndef Common_Defs
  39. #define Common_Defs
  40.  
  41. #define kStr255Len            255        // this length is for NewPtr call, used before making a Toolbox call
  42. #define kNameLen            32        // file name length
  43.  
  44. enum checkboxstate { dechecked,checked };
  45.  
  46. #define kStrangeErr            -1
  47.  
  48. #define kActive                0
  49. #define kInactive            255
  50.  
  51. // ASCII key characters
  52. #define kCrChar                    13        // carriage return key 
  53. #define kDelChar                8        // delete key 
  54. #define kEnterChar                3        // enter char 
  55. #define kPeriodChar                46        // period char 
  56. #define kTabKey                    9        // tab char 
  57. #define kYKey                    121
  58. #define kNKey                    110
  59. #define kEscKey                    27
  60. #define kColon                    58
  61. #define kZero                    48
  62. #define kNine                    57
  63.  
  64. #define    dOK                        1
  65. #define dCancel                    2
  66.  
  67. #define kDelayTick                10        // ticks for button hiliting
  68. #define kWindowWidth            500        // width size for the text window
  69.  
  70. #define    kMaxDocumentCount        100        // maximum number of documents allowed
  71.  
  72. #define    InitialH                16
  73. #define    InitialV                42
  74.  
  75. #define    TopMargin                6
  76. #define    LeftMargin                6
  77. #define    RightMargin                6
  78. #define    BottomMargin            6
  79.  
  80. #define    ScrollResolution        12
  81.  
  82. #define kOpenRsrcID                300
  83.  
  84. // file constants
  85. #define    kFileCreator            'CPAP'
  86. #define    kFileType                'TEXT'
  87. #define kFileTypePICT            'PICT'
  88. #define kOpenRsrcType            'open'
  89.  
  90. // resource constants
  91. #define rIconSuite                128
  92.  
  93. #define iIconSuite                3
  94.  
  95. // alert resources constants:
  96. #define rSaveChangesID            128
  97. #define rRevertID                129
  98. #define rGenericAlertID            130
  99. #define rAboutID                131
  100.  
  101. // resource string constants
  102. #define    rAppStringsID            128
  103. enum {
  104.     sApplicationName = 1,
  105.     sTranslationLockedErr,
  106.     sTranslationErr,
  107.     sOpeningErr,
  108.     sReadErr,
  109.     sWriteToBusyFileErr,
  110.     sBusyOpen,
  111.     sChooseFile,
  112.     sChooseFolder,
  113.     sChooseVolume,
  114.     sCreateFolder,
  115.     sChooseObject
  116. };
  117.  
  118. #define    MenuStringsID            129
  119. enum {
  120.     slCantUndo = 1,
  121.     slUndoDrag,
  122.     slRedoDrag
  123. };
  124.  
  125. // menu resource constants
  126. #define    MenuBarID                128
  127.  
  128. #define    idAppleMenu                128
  129. #define    AboutItem                1
  130.  
  131. #define    idFileMenu                129
  132. #define    NewItem                    1
  133. #define    OpenItem                2
  134. #define    CloseItem                4
  135. #define    SaveItem                5
  136. #define SaveACopyItem            6
  137. #define    RevertItem                7
  138. //=
  139. #define DictionaryItem            9
  140. //=
  141. #define    PageSetupItem            11
  142. #define    PrintItem                12
  143. //=
  144. #define    QuitItem                14
  145.  
  146. #define    idEditMenu                130
  147. #define    iUndo                    1
  148. #define    iCut                    3
  149. #define    iCopy                    4
  150. #define    iPaste                    5
  151. #define    iClear                    6
  152. #define    iSelectAll                7
  153.  
  154. #define idUtilsMenu                131
  155. #define iSelectDir                1
  156. #define iSelectVol                2
  157. #define iSelectObject            3
  158. #define iCreateFolder            5
  159. #define iCustomOpen                7
  160.  
  161. #define kScrollBarWidth         16
  162. #define kScrollBarPos             kScrollBarWidth-1
  163.  
  164. // main document:
  165. typedef struct Document
  166. {
  167.     WindowPtr        theWindow;
  168.     TEHandle        theTE;
  169.     short            docTop;
  170.     RgnHandle        hiliteRgn;
  171.     
  172.     ControlHandle    vScroll;
  173.     ControlHandle    hScroll;
  174.     short            vScrollPos;
  175.     
  176.     short            fRefNum;
  177.     short            dirty;
  178.     
  179.     Handle            undoDragText;
  180.     short            undoSelStart;
  181.     short            undoSelEnd;
  182.     
  183.     short            lastSelStart;
  184.     short            lastSelEnd;
  185.  
  186.     ParamBlockRec    fioParamBlock;            // param block for file I/O operations
  187.     Handle            fPict;
  188.     Handle            fHeader;
  189.     long            fPictLength;
  190.  
  191. } Document;
  192.  
  193.  
  194. // offscreen drawing:
  195. typedef struct WindowOffscreen
  196. {
  197.     CGrafPtr        windowPort;
  198.     GDHandle        windowDevice;
  199.     GWorldPtr        offscreenWorld;
  200. } WindowOffscreen;
  201.  
  202. WindowOffscreen* DrawOffscreen(WindowPtr theWindow);
  203.  
  204.  
  205. #define mBarHeight    (short *)0x0BAA        // Low mem global for menu bar
  206. #define EventQueue  (QHdrPtr)0x14A         // Event queue header (10 bytes)
  207. #define Mouse        ((Point*)0x830)        // processed mouse
  208. #define KeyTime     (long*)0x186        // tickcount when KEYLAST was rec'd 
  209.  
  210. #define TopLeft(aRect)    (* (Point *) &(aRect).top)
  211. #define BotRight(aRect)    (* (Point *) &(aRect).bottom)
  212.  
  213. #define RectWidth(aRect) ((aRect).right - (aRect).left)
  214. #define RectHeight(aRect) ((aRect).bottom - (aRect).top)
  215.  
  216. #define Max(X, Y) ( ((X)>(Y)) ? (X) : (Y) )
  217. #define Min(X, Y) (  ((X)>(Y)) ? (Y) : (X) )
  218.  
  219. #define Pin(VALUE, MIN, MAX) ( ((VALUE) < (MIN)) ? (MIN) : ( ((VALUE) > (MAX)) ? (MAX) : (VALUE) ) )
  220.  
  221. #define kOpenPrefKey            1
  222. #define kSavePrefKey            2
  223. #define kSelectFilePrefKey        3
  224. #define kSelectFolderPrefKey    4
  225. #define kSelectVolumePrefKey    5
  226. #define kNewFolderPrefKey        6
  227. #define kSelectObjectPrefKey    7
  228.         
  229. //**************************************************************
  230.  
  231. // utility routines for detecting keydowns
  232. Boolean ModifierDown(short modifier);
  233. Boolean OptionDown(void);
  234. Boolean ShiftDown(void);
  235. Boolean CommandDown(void);
  236. Boolean ControlDown(void);
  237.  
  238. static SInt16 rnd(SInt16 max);
  239. short RandTween(short low, short high);
  240.  
  241. // file utilities:
  242. OSErr PathNameFromDirID(long dirID, short vRefNum, StringPtr fullPathName, short maxPathLength, short full);
  243. Boolean FSSpecsEq(FSSpec* a, FSSpec* b);
  244. pascal void myEventProc(NavEventCallbackMessage callBackSelctor, NavCBRecPtr callBackParms, NavCallBackUserData callBackUD);
  245.  
  246. // dialog control utilities
  247. void hiliteTheButton(DialogPtr theDialog, short whichItem);
  248. void AdornButton(DialogPtr theDialog, short whichItem);
  249. unsigned char* GetItemStr(DialogPtr theDialog, short theItem, unsigned char* theString);
  250. void PokeItemStr(DialogPtr theDialog, short theItem, unsigned char* theString);
  251. void PokeCtlVal(DialogPtr theDialog, short theItem, short value);
  252. void PokeCtlHilite(DialogPtr theDialog, short theItem, short value);
  253.  
  254. // string utilities
  255. OSType Str2OSType(Str255 theStr);
  256. long MyStrLen(char* s);
  257. long myStringToLong(char* s);
  258. short myStringToShort(char* s);
  259. void myStrCpy(char* dst, char* src);
  260. void myStrCat(char* dst, char* src);
  261. unsigned char* ConcatPP(unsigned char* a,unsigned char* b);
  262. char* MyP2CCopy(unsigned char* psrc,char* ctarget);
  263. unsigned char* MyC2PStr(char* theStr);
  264. char* MyP2CStr(unsigned char* theStr);
  265.  
  266. void DrawIconSuite(short resID, Rect destRect);
  267. void DebugCStr(char* msg);
  268. void AdjustCursor(Point theLoc, RgnHandle theRgn);
  269.  
  270.  
  271. // *******************************************************************
  272.  
  273. // prototypes for 'document.c'
  274. Document* NewDocument(Boolean newAsPICT);
  275. Document* IsDocumentWindow(WindowPtr theWindow);
  276. void DoUndoDrag(void);
  277. pascal void DocumentClickLoop(void);
  278. void DoActivateDocument(Document* theDocument, short activate);
  279. void DoSelectAllDocument(Document* theDocument);
  280. void UpdateWindow(Document* theDocument);
  281. void GrowDocumentWindow(WindowPtr theWindow, Point thePoint);
  282. void DoZoomDocument(Document* theDocument, WindowPtr theWindow, short thePart);
  283. pascal void ScrollProc(ControlHandle theControl, short theCode);
  284. void DocumentHighlightProc(void);
  285. void SizeDocWindow(Document* theDocument);
  286.  
  287. // prototypes for 'files.c'
  288. short DoSaveDocument(Document* theDocument);
  289. void DoNewDocument(Boolean newDocAsPICT);
  290. OSErr DoOpenFile(FSSpec* theFile, Boolean openAsPICT);
  291.  
  292. OSErr DoOpenDocument(void);
  293. OSErr DoOpenDocumentTheOldWay(void);
  294.  
  295. OSErr SaveACopyDocument(Document* theDocument);
  296. OSErr SaveACopyDocumentTheOldWay(Document* theDocument);
  297.  
  298. void DoRevertDocument(Document* theDocument);
  299. void DoRevertDocumentTheOldWay(Document* theDocument);
  300.  
  301. OSErr SaveACopyDocument(Document* theDocument);
  302. OSErr SaveACopyDocumentTheOldWay(Document* theDocument);
  303.  
  304. // prototypes for 'Utilities.c'
  305. short TEIsFrontOfLine(short offset, TEHandle theTE);
  306. short TEGetLine(short offset, TEHandle theTE);
  307. short myTECut(TEHandle theTE);
  308. short myTEPaste(TEHandle theTE, short* spaceBefore, short* spaceAfter);
  309.  
  310. // prototypes for 'Offscreen.c'
  311. void DrawOnscreen(WindowOffscreen* theOffscreen);
  312.  
  313. // prototypes for 'document.c'
  314. void AdjustDocumentView(Document* theDocument);
  315. void AdjustScrollBar(Document* theDocument);
  316. void CloseDocument(Document* theDocument, Boolean quitting);
  317. void DisableUndoDrag(void);
  318. void AddText(Document* theDocument, Ptr text, long len);
  319.  
  320. // prototypes for 'drag.c'
  321. short DragText(Document* theDocument, EventRecord* theEvent, RgnHandle hiliteRgn);
  322.  
  323. // prototypes for 'menu.c'
  324. void AdjustMenus(void);
  325. void DoMenuCommand(long select);
  326.  
  327. // prototypes for 'event.c'
  328. void EventLoop(void);
  329. pascal OSErr MyHandleOAPP(AppleEvent* theAppleEvent, AppleEvent* reply, long handlerRefCon);
  330. pascal OSErr MyHandleODOC(AppleEvent* theAppleEvent, AppleEvent* reply, long handlerRefCon);
  331. pascal OSErr MyHandleQUIT(AppleEvent* theAppleEvent, AppleEvent* reply, long handlerRefCon);
  332.  
  333. #endif // Common_Defs